package com.hefei.customer.service.impl;

import java.util.List;





import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hefei.api.customer.manager.IMenuManager;
import com.hefei.api.customer.manager.impl.MenuManager;
import com.hefei.api.customer.vo.SysMenu;
import com.hefei.api.customer.vo.easyui.PageHelper;
import com.hefei.common.exception.ClientException;
import com.hefei.customer.service.IMenuService;



@Service
public class MenuService implements IMenuService{
	
	
	private IMenuManager menuManager = new MenuManager();
	
	/**
	 * 获取总数
	 * @param user
	 * @return
	 * @throws ClientException 
	 */
	public Long getDatagridTotal(SysMenu menu) throws ClientException {
		return menuManager.getDatagridTotal(menu);  
	}

	/**
	 * 获取一级列表
	 * @param page
	 * @return
	 * @throws ClientException 
	 */
	public List<SysMenu> datagridMenu(PageHelper page) throws ClientException {
		page.setStart((page.getPage()-1)*page.getRows());
		page.setEnd(page.getPage()*page.getRows());
		return menuManager.datagridMenu(page);  
	}
	
	/**
	 * 获取所有列表
	 * @param page
	 * @return
	 * @throws ClientException 
	 */
	public List<SysMenu> getAll(PageHelper page) throws ClientException {
		page.setStart((page.getPage()-1)*page.getRows());
		page.setEnd(page.getPage()*page.getRows());
		return menuManager.getAll(page);  
	}

	public void deleteMenuById(Integer menuId) throws ClientException {
		menuManager.deleteMenuById(menuId);
	}

	public SysMenu getMenuById(Integer menuId) throws ClientException {
		return menuManager.getMenuById(menuId);
	}

	public List<SysMenu> listAllParentMenu() throws ClientException {
		return menuManager.listAllParentMenu();
	}

	public void saveMenu(SysMenu menu) throws ClientException {
		if(menu.getId()!=null && menu.getId().intValue()>0){
			menuManager.updateMenu(menu);
		}else{
			menuManager.insertMenu(menu);
		}
	}

	public List<SysMenu> listSubMenuByParentid(Integer parentid) throws ClientException {
		return menuManager.listSubMenuByParentid(parentid);
	}
	
	public List<SysMenu> listAllMenu() throws ClientException {
		List<SysMenu> rl = this.listAllParentMenu();
		for(SysMenu menu : rl){
			List<SysMenu> subList = this.listSubMenuByParentid(menu.getId());
			menu.setSubMenu(subList);
		}
		return rl;
	}

	public List<SysMenu> listAllSubMenu() throws ClientException{
		return menuManager.listAllSubMenu();
	}


	
}
